import { getAddress, getOrder } from '@/api'

export default {
  namespaced: true,
  actions: {
    async getUserAddress(context) {
      let result = await getAddress()
      if (result.code === 200) {
        context.commit('GETUSERADDRESS', result.data)
        return 'ok'
      } else {
        return Promise.reject(new Error('failed'))
      }

    },
    async getUserOrder(context) {
      let result = await getOrder()
      if (result.code === 200) {
        context.commit('GETUSERORDER', result.data)
      } else {
        return Promise.reject(new Error('failed'))
      }
    }
  },
  mutations: {
    GETUSERADDRESS(state, val) {
      state.address = val
    },
    GETUSERORDER(state, val) {
      state.order = val
    }
  },
  state: {
    address: [],
    order: {}
  },
  getters: {
    detailArrayList(state) {
      return state.order.detailArrayList
    }
  }
}